import ArrayUtil from '@/ArrayUtil';
import BaseUtil from '@/BaseUtil';
import STimer from '@/STimer';
import { OrderId } from '@/globals/order';
import SummonCommon from 'code/Core/Common/SummonCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 恶魔增长
 **/
export default class SS_DemoonIncrease extends AbilityBase {
    static instance: SS_DemoonIncrease;
    constructor(id: string = 'Aemz') {
        super(id);
        SS_DemoonIncrease.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    vks = ['nbal', 'ndqv', 'ndqv', 'nfel', 'nfel', 'nfel', 'nfel'];
    init() {}
    db: Map<number, any> = new Map();
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let ef = AddSpecialEffect('Abilities\\Spells\\Undead\\RegenerationAura\\ObsidianRegenAura.mdl', tarX, tarY);
        let st = BaseUtil.onTimer(1, this.timerLoop.bind(this));
        this.db.set(st.uuid, { caster: source, x: tarX, y: tarY, ef });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    timerLoop(c: number, t: STimer) {
        let { caster, x, y, ef } = this.db.get(t.uuid);
        if (GetUnitCurrentOrder(caster) == OrderId.Stampede) {
            let id = ArrayUtil.randomElement(this.vks);
            let lv = this.getAbilityLevel(caster);
            let fp = UnitCommon.getFullProperty(caster);

            SummonCommon.summon({
                unitTypeId: id,
                caster,
                x,
                y,
                attr: {
                    life: fp * lv * 0.6,
                    attack: 10 * lv + (fp * lv) / 20,
                    附加护甲: 10 * lv + (fp * lv) / 20,
                    附加魔抗: 10 * lv + (fp * lv) / 20,
                },
                lifeTime: 20 + 10 * lv,
            });
        } else {
            DestroyEffect(ef);
            this.db.delete(t.uuid);
            return false;
        }
        if (c >= 6) {
            DestroyEffect(ef);
            this.db.delete(t.uuid);
        }
        return c < 6;
    }
}
